#ifndef __TICKET_DEVICE_H__
#define __TICKET_DEVICE_H__

#include "list.h"

#define ORIGIN_PLACE_SIZE       (20)
#define DESTINATION_SIZE        (20)
#define DEPARTURE_TIME_SIZE     (6)
#define ARRIVAL_TIME_SIZE       (6)
#define PRICE_SIZE              (5)
#define TICKET_NUM_SIZE         (4)
#define TRAIN_NUM_SIZE          (5+1)
#define TO_DATE_SIZE            (10+1)
#define USER_TICKET_ID_SIZE            (11)
#define TICKET_TYPE_SIZE        (20)
#define NAME_SIZE           (20)
#define CITIZEN_ID_SIZE     (18 + 1)
#define PHONE_NUM_SIZE      (11 + 1)

struct ticket {
    char origin_place[ORIGIN_PLACE_SIZE];
    char destination[DESTINATION_SIZE];
    char train_number[TRAIN_NUM_SIZE];
    char departure_time[DEPARTURE_TIME_SIZE];
    char arrival_time[ARRIVAL_TIME_SIZE];
    char type1_price[PRICE_SIZE];
    char type2_price[PRICE_SIZE];
    char type3_price[PRICE_SIZE];
    char type4_price[PRICE_SIZE];
    char date[TO_DATE_SIZE];
    char ticket_type1_num[TICKET_NUM_SIZE];
    char ticket_type2_num[TICKET_NUM_SIZE];
    char ticket_type3_num[TICKET_NUM_SIZE];
    char ticket_type4_num[TICKET_NUM_SIZE];
    struct list_head list;
};

struct user_ticket {
    char id[USER_TICKET_ID_SIZE];
    char name[NAME_SIZE];
    char citizen_id[CITIZEN_ID_SIZE];
    char phone_num[PHONE_NUM_SIZE];
    char origin_place[ORIGIN_PLACE_SIZE];
    char destination[DESTINATION_SIZE];
    char train_number[TRAIN_NUM_SIZE];
    char departure_time[DEPARTURE_TIME_SIZE];
    char arrival_time[ARRIVAL_TIME_SIZE];
    char price[PRICE_SIZE];
    char date[TO_DATE_SIZE];
    char ticket_type[TICKET_TYPE_SIZE];
    struct list_head list;
};

extern int ticket_init(struct list_head *ticket_head, struct list_head *user_ticket_head);
extern int build_ticket_buffer(char *ticket_buffer, struct list_head *temporary_head);
extern int build_all_ticket_buffer(char *ticket_buffer, struct list_head *ticket_head);
extern int build_ticket_buffer_2(char *ticket_buffer, struct list_head *temporary_head);
extern int ticket_destroy(struct list_head *ticket_head, struct list_head *user_ticket_head);
extern void write_user_ticket_file_onetime(struct list_head *user_ticket_head);
extern void write_ticket_file_onetime(struct list_head *ticket_head);
extern int compare_ticket(char *ticket1, char *ticket2);

#endif